From 47c6f914c3985c5719edf710848d372fc2640b26 Mon Sep 17 00:00:00 2001 From: Justin Burkett Date: Tue, 20 Dec 2016 15:56:35 -0500 Subject: [PATCH] Add which-key-max-display-columns See #157 --- which-key.el | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/which-key.el b/which-key.el index 6545026c7f2..9a44be9b458 100644 --- a/which-key.el +++ b/which-key.el @@ -256,6 +256,12 @@ and nil. Nil turns the feature off." :group 'which-key :type 'integer) +(defcustom which-key-max-display-columns nil + "The maximum number of columns to display in the which-key +buffer. nil means don't impose a maximum." + :group 'which-key + :type 'integer) + (defcustom which-key-side-window-location 'bottom "Location of which-key popup when `which-key-popup-type' is side-window. Should be one of top, bottom, left or right. You can also specify @@ -1608,7 +1614,7 @@ Returns a plist that holds the page strings, as well as metadata." (let ((cols-w-widths (mapcar #'which-key--pad-column (which-key--partition-list avl-lines keys))) - (page-width 0) (n-pages 0) (n-keys 0) + (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0) page-cols pages page-widths keys/page col) (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width) ;; give up if no columns fit @@ -1617,17 +1623,21 @@ metadata." (while cols-w-widths ;; start new page (cl-incf n-pages) - (setq col (pop cols-w-widths) - page-cols (list (cdr col)) - page-width (car col) - n-keys (length (cdr col))) + (setq col (pop cols-w-widths)) + (setq page-cols (list (cdr col))) + (setq page-width (car col)) + (setq n-keys (length (cdr col))) + (setq n-columns 1) ;; add additional columns as long as they fit (while (and cols-w-widths + (or (null which-key-max-display-columns) + (< n-columns which-key-max-display-columns)) (<= (+ (caar cols-w-widths) page-width) avl-width)) (setq col (pop cols-w-widths)) (push (cdr col) page-cols) (cl-incf page-width (car col)) - (cl-incf n-keys (length (cdr col)))) + (cl-incf n-keys (length (cdr col))) + (cl-incf n-columns)) (push (which-key--join-columns page-cols) pages) (push n-keys keys/page) (push page-width page-widths)) -- 2.30.2